import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) {

        StringBuilder stringBuilder = new StringBuilder();
//        stringBuilder.delete();
        System.out.println(restoreIpAddresses("101023"));

    }

    static List<String> ret = new ArrayList<>();
    static StringBuilder stringBuilder = new StringBuilder();
    public static List<String> restoreIpAddresses(String s) {
        if(s.length() > 12) return ret;
        back(s,0,0);
        return ret;
    }
    //  number : ip段数量
    public static void back(String s,int start,int pointNum){
        if(pointNum == 3){// ,个数为3,说明分为了四段
            if(start == s.length() ){
                ret.add(stringBuilder.toString());
            }
            return;
        }
        for(int end = start + 1; end <= s.length(); end++){
            String str = s.substring(start,end);
            if(isValid(str)){
                stringBuilder.append(str);
                if(pointNum < 3){
                    stringBuilder.append(".");
                }
                back(s,end,pointNum+1);
                stringBuilder.delete(start+pointNum,end+pointNum+1);
            }
        }
    }
    public static boolean isValid(String str){
        if(str.length() > 3) return false;
        int num = Integer.parseInt(str);
        if(num == 0 && str.length() == 1) return true;
        if(num > 0 && num <= 255){
            return true;
        }
        return false;
    }
}
